<template>
	<view class="view_desc_card">
		<view class="card_empty" v-if="!Object.keys(data || {}).length">
			<text>暂未找到货品信息~</text>
		</view>
		<view v-else class="card_main" id="card_info">
			<view class="card_info">
				<view class="card_list">
					<template v-for="(item,index) in cols">
						<view v-if="!item.show || item.show(data)" :key="index" class="card_item">
							<text class="item_label">{{ item.label }}:</text>
							<text class="item_desc">{{data[item.key]}}</text>
						</view>
					</template>
				</view>
				<image class="card_bar_img" :src="data['goods_bar_code']" />
			</view>
			<image class="card_img" :src="data['goods_qr_code']" />
		</view>
		<view v-if="btn" class="card_bottom">
      <button type="warn" @click="goDel">移除</button>
			<button type="primary" @click="goPrint">打印</button>
		</view>
	</view>
</template>

<script>
	export default {
		props:{
			btn:{
				type:Boolean,
				default:true,
			},
			data:{
				type:Object,
				default:()=>{
					return {}
				}
			}
		},
		emits:['del','print'],
		data() {
			return {
				cols:[
					{
						label:'公司名称',
						key:'company'
					},
					{
						label:'生产日期',
						key:'goods_at'
					},
					{
						label:'货号',
						key:'goods_code'
					}
				]
				
			};
		},
		methods:{
			goDel(){
				this.$emit('del')
			},
			goPrint(){
				this.printSection('card_info')

				// this.$emit('print')
			},
			 printSection(sectionId) {
					var printWindow = window.open('', '_blank');
					printWindow.document.write('<html><head><title>Print Section</title>');
					printWindow.document.write('</head><body >');
					printWindow.document.write(document.getElementById(sectionId).innerHTML);
					printWindow.document.write('</body></html>');
					printWindow.document.close();
					printWindow.print();
			}
		}
	}
</script>

<style lang="scss">
.view_desc_card{
	width: 100%;
	height: auto;
	padding: 0 25rpx 0rpx;
	.card_empty{
		min-height: 240rpx;
		padding: 40rpx;
		text-align: center;
		color: #999;
	}
	.card_main{
		display: flex;
		align-items: flex-start;
		justify-content: space-between;
		padding-bottom: 25rpx;
		.card_img{
			width: 240rpx;
			height: 240rpx;
			object-fit: cover;
			border-radius: 10rpx;
			border: 1px solid #ddd;
		}
		.card_bar_img{
			width: 270rpx;
			height: 100rpx;
			margin-top: 10rpx;
		}
		.card_info{
			width: calc(100% - 240rpx - 25rpx);
			height: 100%;
			min-height: 200rpx;
			margin-right: 25rpx;
			display: flex;
			flex-direction: column;
			align-items: flex-start;
			// justify-content: space-between;

		}
	}
	.card_title{
		font-size: 28rpx;
		color: #333;
		text-align: justify;
		line-height: 38rpx;
		margin-bottom: 20rpx;
	}
	.card_list{
		width: 100%;
		height: auto;
		.card_item{
			font-size: 28rpx;
			color: #333;
			text-align: justify;
			line-height: 36rpx;
			.item_label{
				display: inline-block;
				width: 5em;
			}
			&+.card_item{
				margin-top: 10rpx;
			}
		}
	}
	.card_bottom{
		width: 100%;
		height: auto;
		border-top: 1rpx solid #dcdcdc;
		padding: 20rpx 30rpx;
		display: flex;
		align-items: center;
		justify-content: flex-end;
		font-size: 24rpx;
		color: #666;
		line-height: 34rpx;
		text-align: justify;
		button{
			min-width: 140rpx;
			height: 60rpx;
			font-size: 24rpx;
			border-radius: 10rpx;
			display: flex;
			align-items: center;
			justify-content: center;
			margin-left: unset;
			margin-right: unset;
			&+button{
				margin-left: 20rpx;
			}
			&.error{
				background: red;
				color: #fff;
			}
		}
	}
}

</style>
